package jp.co.jmas.jmasvideo;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.jmas.jmasvideo.dao.PMF;
import jp.co.jmas.jmasvideo.dao.UserData;

/**
 *
 *
 */
@SuppressWarnings("serial")
public class GetUserData extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		resp.setContentType("text/html");
		PrintWriter pw = resp.getWriter();

		PersistenceManager pm = PMF.get().getPersistenceManager();
		String query = "select from " + UserData.class.getName();
		@SuppressWarnings("unchecked")
		List<UserData> list = (List<UserData>) pm.newQuery(query).execute();

		for (UserData user : list) {
			pw.println("<p>ID  : " + user.getId() + "</p>");
			pw.println("<p>User: " + user.getName() + "</p>");
			pw.println("<p>Mail: " + user.getMail() + "</p>");

			pw.print("<p>Distribution  : ");
			List<String> dist = user.getDistribution();
			for (String address : dist) {
				pw.print(address + ", ");
			}
			pw.println("</p>");
		}
	}
}
